from config import db
from datetime import datetime


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 用户id
    username = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    name = db.Column(db.String(10), nullable=True)  # 真名
    sex = db.Column(db.String(10), nullable=True)
    address = db.Column(db.String(255), nullable=True)
    email = db.Column(db.String(100), nullable=True)
    phone = db.Column(db.String(15), nullable=True)
    avater = db.Column(db.String(255), default='https://profile.csdnimg.cn/D/3/A/0_weixin_63576473')  # 头像
    birthdate = db.Column(db.String(20), nullable=True)
    createTime = db.Column(db.String(255))
    loginTime = db.Column(db.String(255))
    role = db.Column(db.String(20), nullable=False, default='user')  # 权限控制
    # active = db.Column(db.Boolean, default=False)  # 这里标记软删除
    # level = db.Column(db.Integer, nullable=False, default=1)


# 商品种类
class GoodsType(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(40), unique=False)
    num = db.Column(db.Integer, default=0)


# 商品信息表
class Goods(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 商品编号
    name = db.Column(db.String(40), unique=False)  # 商品名称
    type = db.Column(db.Integer)  # 商品类别
    price = db.Column(db.Integer, nullable=True)  # 商品价格
    outline = db.Column(db.String(255), nullable=True)  # 商品简介
    img_url = db.Column(db.String(255), nullable=True)  # 商品图片
    link_url = db.Column(db.String(255), nullable=True)


class ShopCar(db.Model):
    # 购物车表
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 购物车id
    user_id = db.Column(db.Integer)  # 用户id,参照User表的id
    good_id = db.Column(db.Integer, nullable=False)  # 商品编号
    name = db.Column(db.String(40), nullable=False)
    price = db.Column(db.Float, nullable=True)  # 商品价格
    number = db.Column(db.Integer, nullable=True)
    type = db.Column(db.Integer)  # 商品类别
    outline = db.Column(db.String(255), nullable=True)  # 商品简介
    img_url = db.Column(db.String(255), nullable=True)  # 商品图片
    link_url = db.Column(db.String(255), nullable=True)


class Orders(db.Model):
    # 订单表
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 订单id
    user_id = db.Column(db.Integer)  # 用户id,参照User表的id
    good_id = db.Column(db.Integer, nullable=False)  # 商品编号
    name = db.Column(db.String(40), nullable=False)
    price = db.Column(db.Float, nullable=True)  # 商品价格
    number = db.Column(db.Integer, nullable=True)
    type = db.Column(db.Integer)  # 商品类别
    outline = db.Column(db.String(255), nullable=True)  # 商品简介
    img_url = db.Column(db.String(255), nullable=True)  # 商品图片
    link_url = db.Column(db.String(255), nullable=True)
    create_time = db.Column(db.String(255))


class Comments(db.Model):
    # 评论表
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(20),nullable=False)
    good_id = db.Column(db.Integer, nullable=False)
    star = db.Column(db.Integer)  # 商品类别
    comment_time = db.Column(db.String(255))
    comment=db.Column(db.String(255), nullable=True)


# class Court(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
#     number = db.Column(db.Integer, default=0)  # 记录商品种类


class ShopThing(db.Model):  # 页面展示
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 商品编号
    name = db.Column(db.String(40), unique=False)  # 商品名称
    type = db.Column(db.Integer)  # 商品类别
    price = db.Column(db.Integer, nullable=True)  # 商品价格
    outline = db.Column(db.String(255), nullable=True)  # 商品简介
    img_url = db.Column(db.String(255), nullable=True)  # 商品图片
    link_url = db.Column(db.String(255), nullable=True)


class ma_email(db.Model):  # 邮箱验证码存储
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(100))
    ma = db.Column(db.String(100))


class History(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer)
    good_id = db.Column(db.Integer, nullable=False)
    type = db.Column(db.Integer)
    createTime = db.Column(db.String(255))


# class Comment(db.Model):
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
#     username = db.Column(db.String(20), unique=True, nullable=False)
#     good_id = db.Column(db.Integer, nullable=False)
#     star = db.Column(db.Integer)  # 商品类别
